package dao;

import entity.Vegetable;
import util.DBMannager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class VegetableUpdataDao {

    public boolean updataVegetable(Vegetable vegetable) throws SQLException {
        boolean flag = false;
        Connection connection= DBMannager.getConnection();
        String sql="update vegetable set planttime=?,number=?,price=?,vstatus=? where vegename=?";
        //用蔬菜名做主键，修改种植日期，数量，价格，状态
        PreparedStatement ps=null;
        ps=connection.prepareStatement(sql);

        ps.setString(5,vegetable.getVegename());
        ps.setDate(1,vegetable.getPlanttime());
        ps.setInt(2,vegetable.getNumber());
        ps.setBigDecimal(3,vegetable.getPrice());
        ps.setInt(4,vegetable.getVstatus());

        flag=ps.executeUpdate()>0?true:false;

//        if(ps.executeUpdate()!=0){    //当数据进行变化时executeUpdate会赋予任意常数值，否则为0
//            flag=true;
//        }else {
//            flag=false;
//        }

        return flag;
    }

}
